﻿using System.Collections.Generic;

namespace OrgDataSource
{
    internal static class DataSourceFactory
    {
        private static readonly object Lock = new object();
        private static IDictionary<string, IOrgDS> _services;

        public static IOrgDS GetService(string dataType)
        {
#if DEBUG
            _services = null;
#endif
            if (_services == null)
            {
                lock (Lock)
                {
                    if (_services == null)
                    {
                        _services = new Dictionary<string, IOrgDS>
                                        {
                                            {"company", new CompanyDS()},
                                            {"companylist", new CompanyDS()},
                                            {"companyapplist", new CompanyDS()},
                                            {"companybranchs", new CompanyDS()},
                                            {"application", new ApplicationDS()},
                                            {"applicationlist", new ApplicationDS()},
                                            {"apptasklist", new ApplicationDS()},
                                            {"account", new AuthenticationDS()},
                                            {"certificate", new AuthenticationDS()},
                                            {"loginticket", new AuthenticationDS()},
                                            {"certticket", new AuthenticationDS()},
                                            {"pageticket", new AuthenticationDS()},
                                            {"branch", new BranchDS()},
                                            {"branchlist", new BranchDS()},
                                            {"branchmemberlist", new BranchDS()},
                                            {"branchmemberdetail", new BranchDS()},
                                            {"errorlist", new ErrorDS()},
                                            {"group", new GroupDS()},
                                            {"groupmember", new GroupDS()},
                                            {"grouplist", new GroupDS()},
                                            {"groupmemberlist", new GroupDS()},
                                            {"member", new MemberDS()},
                                            {"membergrouplist", new MemberDS()},
                                            {"memberdetail", new MemberDS()},
                                            {"usertasklist", new MemberDS()},
                                            {"relateoulist", new OUDS()},
                                            {"searchouinfo", new OUDS()},
                                            {"rolemember", new RoleDS()},
                                            {"roleauthority", new RoleDS()},
                                            {"rolelist", new RoleDS()},
                                            {"task", new TaskDS()},
                                            {"uservar", new UserVarDS()}
                                        };
                    }
                }
            }
            var key = dataType.ToLower();
            if (_services.ContainsKey(key))
                return _services[key];
            return null;
        }
    }
}
